define(['./../initial'], function() {
    var app = angular.module('App.userNotice');
    app.value('version', '1ddff-a1ac1-sdferefg-11fslaleou-eret3j8a85d');

    app.directive('updateNotice', ['version', '$timeout', '$rootScope',
        function(version, $timeout, $rootScope) {
            return {
                restrict: 'A',
                templateUrl: 'partials/updateNotice.html',
                link: function(scope, iElement, iAttrs) {
                    var oldV = window.localStorage.getItem('version');
                    var update = $('#update');

                    scope.updateObj = {
                        "time": "2014-12-3",
                        "updateInfos": [{
                            "title": "自定义查询",
                            "info": "查询方式更加灵活,方便追踪自动化数据."
                        }]
                    };

                    if (oldV != version) {
                        window.localStorage.setItem('noNotice', false);
                        showNotice();
                    } else {
                        var noNotice = window.localStorage.getItem('noNotice');
                        if (!noNotice || noNotice === "false") {
                            showNotice();
                        }
                    }

                    function showNotice() {
                        $timeout(function() {
                            if ($rootScope.smallScreen === false) {
                                update.addClass('show');
                            }
                        }, 2000);
                    }



                    scope.iKnowBtn = function() {
                        update.removeClass('show').addClass('hide');
                        window.localStorage.setItem('version', version);
                    };

                    scope.noNoticeBtn = function() {
                        scope.iKnowBtn();
                        window.localStorage.setItem('noNotice', true);
                    };

                }
            };
        }
    ]);
});
